﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CMS.Converts
{
    //转换器一定要继承IValueConverter接口
    public class StringToIntConverts : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return "管理员";
            if(int.TryParse(value.ToString(),out int role))
            {
                switch (role)
                {
                    case 0:return "管理员";
                    case 1: return "操作员";
                    case 3: return "挂壁员";
                    case 4: return "打工人";
                    default:break;
                }
            }
            //默认情况
            return "操作员";
        }
        //前段转成后端的
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int result = 0;
            if (value == null) return 0;
            switch (value.ToString())
            {
                case "管理员": result = 0; break;
                case "操作员": result = 1; break;
                case "挂壁员": result = 2; break;
                case "打工人": result = 3; break;
                default: break;
            }
            return result;
           
        }
    }
}
